<?php
use app\assets\FileUploadAsset;
use app\assets\MaskedInputAsset;
use app\models\AdLocation;
use app\models\KeyMap;
use app\widgets\FileUploadWidget;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;

/**
 * @var $this yii\web\View
 * @var $model app\models\Ad
 */

$this->title = '广告添加/修改';
$this->params['breadcrumbs'][] = '广告管理';
$this->params['breadcrumbs'][] = $this->title;
FileUploadAsset::register($this);
MaskedInputAsset::register($this);
?>
<?php $form = ActiveForm::begin();?>
    <?php echo Html::activeHiddenInput($model, 'id');?>
    <?php echo $form->field($model, 'name');?>
    <?php echo $form->field($model, 'lid')->dropDownList(ArrayHelper::map(AdLocation::find()->all(), 'id', function($item, $default) {return $item['name'] . ' ' . KeyMap::getValue('ad_type', $item['type']) . ' ' . $item['width'] . 'x' . $item['height'];}));?>
    <?php echo $form->field($model, 'txt');?>
    <?php echo $form->field($model, 'img_fid')
    ->hint($model->img_fid > 0 ? Html::img($model->img->getUrl(), ['width'=>100]) : ' ')
    ->widget(FileUploadWidget::className(), ['url'=>Url::to(['/admin/ad/upload']), 'callback'=>'uploadCallback']);?>
    <script>
    function uploadCallback(fid, url) {
        $('#ad-img_fid').val(fid);
        $('.field-ad-img_fid .hint-block').html('<img src="' + url + '" width="100" />');
    }
    </script>
    <?php echo $form->field($model, 'url');?>
    <?php echo $form->field($model, 'start_time')->textInput(['value'=>Yii::$app->formatter->asDatetime($model->start_time), 'class'=>'form-control masked', 'data-mask'=>'9999-99-99 99:99:99']);?>
    <?php echo $form->field($model, 'end_time')->textInput(['value'=>Yii::$app->formatter->asDatetime($model->end_time), 'class'=>'form-control masked', 'data-mask'=>'9999-99-99 99:99:99']);?>
    <?php echo $form->field($model, 'status')->radioList(KeyMap::getValues('ad_status'));?>
    <?php echo $form->field($model, 'contact');?>
    <?php echo $form->field($model, 'email');?>
    <?php echo $form->field($model, 'mobile');?>
    <div class="form-group">
        <div class="col-lg-offset-1 col-lg-11">
            <button type="button" class="btn btn-default" onclick="window.history.go(-1);"><i class="ace-icon fa fa-arrow-left bigger-110"></i>返回</button>
            <button type="submit" class="btn btn-primary"><i class="ace-icon fa fa-check bigger-110"></i>保存</button>
            <button type="reset" class="btn btn-warning"><i class="ace-icon fa fa-undo bigger-110"></i>重置</button>
        </div>
    </div>
<?php $form->end();?>
